package com.lfd.mapstruct;

import com.lfd.mapstruct.struct.User;
import com.lfd.mapstruct.struct.UserDTO;
import com.lfd.mapstruct.struct.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class MapStructApplication implements CommandLineRunner {
    @Autowired
    private UserService userService;


    public static void main(String[] args) {
        SpringApplication.run(MapStructApplication.class, args);
    }

    @Override
    public void run(String... args) throws Exception {
        UserDTO userDTO = UserDTO.builder().email("email@QQ.COM").id(1L).
                name("张三").build();
//                cid(2L).
        User user = userService.convertToEntity(userDTO);
        System.out.println("=========user==" + user);
        UserDTO userDTO2 = userService.convertToDTO(user);
        System.out.println("=========userDTO2==" + userDTO2);

        User user1 = userService.cloneUser(user);
        System.out.println("=========user1==" + user1);
    }
}
